export const sortData = (dataSource: any[], type: string, sortKey: string) => {
  const source = JSON.parse(JSON.stringify(dataSource))
  if (type === 'none') {
    return [...dataSource]
  }
  const data = source.sort((prev:any, curr:any) => {
    const a = parseFloat(prev[sortKey])
    const b = parseFloat(curr[sortKey])
    if (a - b < 0) {
      return -1
    }
    if (a - b > 0) {
      return 1
    }
    return 0
  })
  return type === 'asc' ? data : data.reverse()
}
export const getColor = (str: string) => {
  const num = parseFloat(str)
  if (num > 0) {
    return 'red'
  }
  if (num < 0) {
    return 'green'
  }
  return ''
}
export const sortDataTime = (dataSource: any[], type: string, sortKey: string) => {
  const source = JSON.parse(JSON.stringify(dataSource))
  if (type === 'none') {
    return [...dataSource]
  }
  const data = source.sort((prev:any, curr:any) => {
    const a = Number(prev[sortKey].replace(/\D/g, ''))
    const b = Number(curr[sortKey].replace(/\D/g, ''))
    if (a - b < 0) {
      return -1
    }
    if (a - b > 0) {
      return 1
    }
    return 0
  })
  return type === 'asc' ? data : data.reverse()
}
